﻿Imports Microsoft.DirectX.Direct3D
Imports Microsoft.DirectX
Imports Commander_Wars.Spieletools
Public Class ObjektDropDownMenue
    Inherits Objekt2D


    Enum AnzeigeModi
        Text
        Farben
    End Enum
    ''' <summary>
    ''' Die Maximale Anzahl an Items, die wir anzeigen.
    ''' </summary>
    ''' <remarks></remarks>
    Const MaxItems As Integer = 10

    ''' <summary>
    ''' wenn true haben wir auf diesen Regler Button geklickt und wechseln hoch runter
    ''' </summary>
    ''' <remarks></remarks>
    Dim Aktiv As Boolean = False
    ''' <summary>
    ''' Wenn wir diesen Regler Button benutzen
    ''' </summary>
    ''' <remarks></remarks>
    Dim Buttonaktiv As Integer = 0
    ''' <summary>
    ''' Die Tags der Items.
    ''' </summary>
    ''' <remarks></remarks>
    Dim Tags() As String = {}
    ''' <summary>
    ''' Die Uebersetzten Items
    ''' </summary>
    ''' <remarks></remarks>
    Public Items() As String = {}
    ''' <summary>
    ''' Das Ausgewaehlte Item als Tag
    ''' </summary>
    ''' <remarks></remarks>
    Dim SelectedItemTag As String
    ''' <summary>
    ''' Das ausgewaehlte Item.
    ''' </summary>
    ''' <remarks></remarks>
    Dim SelectedItem As String
    ''' <summary>
    ''' Ob wir Text oder Farben malen.
    ''' </summary>
    ''' <remarks></remarks>
    Dim AnzeigeModus As AnzeigeModi
    ''' <summary>
    ''' Ab hier werden die Items gemalt
    ''' </summary>
    ''' <remarks></remarks>
    Dim StartIndex As Integer = 0
    ''' <summary>
    ''' Das TextObjekt zum Malen
    ''' </summary>
    ''' <remarks></remarks>
    Dim Text As ObjektText
    ''' <summary>
    ''' Werte sind 1 nach unten und -1 Nach Oben.
    ''' </summary>
    ''' <remarks></remarks>
    Dim Ausfahrrichtung As Integer = 1
    ''' <summary>
    ''' Das Cursorrechteck, was gemalt wird wenn wir was ausgewaehlt haben.
    ''' </summary>
    ''' <remarks></remarks>
    Dim CursorRechteck As Rectangle = Nothing
    Dim Frame2 As Integer = 0
    Dim Netzmodus As Boolean = False
    ''' <summary>
    ''' Gibt je nach Modus eine Farbe oder einen String zurueck!
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetItem()
        Select Case AnzeigeModus
            Case AnzeigeModi.Farben
                Return Color.FromArgb(CInt(SelectedItemTag))
            Case Else
                Return SelectedItemTag
        End Select
    End Function
    Public Sub SetItem(ByVal Tag As String)
        SelectedItemTag = Tag
        SelectedItem = Sprachconverter.Translate(Tag)
    End Sub
    Public Sub SetToExistingItem(ByVal Tag As String)
        For Each T In Tags
            If T = Tag Then
                SelectedItemTag = Tag
                SelectedItem = Sprachconverter.Translate(Tag)
                Exit Sub
            End If
        Next
        If Tags.Length > 0 Then
            SelectedItemTag = Tags(0)
            SelectedItem = Sprachconverter.Translate(SelectedItemTag)
        End If
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <returns>-1 Bedeutet nicht aus der Liste</returns>
    ''' <remarks></remarks>
    Public Function IsItemOutOfList() As Integer
        For I = 0 To Tags.Length - 1
            If Tags(I) = SelectedItemTag Then
                Return I
            End If
        Next
        Return -1
    End Function
    Public Sub New(ByVal X As Integer, ByVal Y As Integer, ByVal Items As Color(), ByVal Fixed As PointF, Optional ByVal Netzmodus As Boolean = True, Optional ByVal Handler As ObjektPanel = Nothing)
        MyBase.New("DropdownMenue", New Rectangle(0, 0, 32, 21), New Point(X, Y), Fixed, Handler)
        Dim Item(Items.Length - 1) As String
        For I = 0 To Items.Length - 1
            Item(I) = Items(I).ToArgb.ToString
        Next
        Tags = Item
        AnzeigeModus = AnzeigeModi.Farben
        LoadStuff(Item, Netzmodus)
        Dim Int As Integer = MaxItems
        If Int * 21 + 21 + GetRealY() > DataSettings.BildschirmHoehe - 20 Then
            Ausfahrrichtung = -1
            StartIndex = Items.Length - MaxItems
            If StartIndex < 0 Then StartIndex = 0
        End If
    End Sub
    Public Sub New(ByVal X As Integer, ByVal Y As Integer, ByVal Items As String(), ByVal Fixed As PointF, Optional ByVal Netzmodus As Boolean = True, Optional ByVal Handler As ObjektPanel = Nothing)
        MyBase.New("DropdownMenue", New Rectangle(0, 0, 32, 21), New Point(X, Y), Fixed, Nothing)
        Tags = Items
        Dim Item(Items.Length - 1) As String
        For I = 0 To Items.Length - 1
            Item(I) = Sprachconverter.Translate(Items(I))
        Next
        LoadStuff(Item, Netzmodus)
        AnzeigeModus = AnzeigeModi.Text
        'Da Groessen und andere Dinge erst noch berechnet wurden!
        Me.Handler = Handler
        If Me.Handler IsNot Nothing Then
            Me.Handler.AddObjekt(Me)
        End If
        Dim Int As Integer = MaxItems
        If MaxItems > Items.Length Then Int = Items.Length
        If Int * 21 + 21 + GetRealY() > DataSettings.BildschirmHoehe - 20 Then
            Ausfahrrichtung = -1
            StartIndex = Items.Length - MaxItems
            If StartIndex < 0 Then StartIndex = 0
        End If
    End Sub
    ''' <summary>
    ''' Laedt alle Daten
    ''' </summary>
    ''' <param name="Items"></param>
    ''' <remarks></remarks>
    Private Sub LoadStuff(ByVal Items() As String, ByVal Netzmodus As Boolean)
        Me.Netzmodus = Netzmodus
        Me.Items = Items
        Bildgroesse.Height = 21
        Text = New ObjektText(Nothing, 0, 0, Nothing, Schriftengine.Schriftarten.Arial, 11, FontStyle.Regular, , 4)
        'Hier werden Dinge unterschiedlich geladen
        Select Case AnzeigeModus
            Case AnzeigeModi.Farben
                'Hier sind Breiten und Hoehen fest
                Bildgroesse.Width = 19

            Case AnzeigeModi.Text
                'Jetzt muessen wir alles Berechnen
                For I = 0 To Items.Length - 1
                    Dim B As Integer
                    Schriftengine.MeasureSpriteLocker.Lock()
                    Try
                        Grafikengine.Sprite.Transform = Matrix.Identity
                        B = Text.GetSchriftart.MeasureString(Schriftengine.MeasureSprite, Items(I), DrawTextFormat.None, Color.Black).Width
                    Catch
                        I -= 1
                    End Try
                    Schriftengine.MeasureSpriteLocker.Unlock()
                    If B > Bildgroesse.Width Then
                        Bildgroesse.Width = B
                    End If
                Next
                Bildgroesse.Width += 2
        End Select
        If Items.Length > 0 Then
            SelectedItem = Items(0)
            SelectedItemTag = Tags(0)
        End If
        Bildgroesse.X = Koordinaten.X
        Bildgroesse.Y = Koordinaten.Y

    End Sub
    Public Sub SetNetzmodus(ByVal Modus As Boolean)
        Netzmodus = Modus
    End Sub
    ''' <summary>
    ''' Wir legen die neuen Items fest
    ''' </summary>
    ''' <param name="Items"></param>
    ''' <remarks></remarks>
    Public Sub SetItems(ByVal Items() As String)
        Tags = Items
        Array.Resize(Me.Items, Items.Length)
        For I = 0 To Me.Items.Length - 1
            Me.Items(I) = Sprachconverter.Translate(Items(I))
        Next
    End Sub
    ''' <summary>
    ''' Gibt den Ort des Items zurueck
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetItemNumber() As Integer
        For I = 0 To Tags.Length - 1
            If Tags(I) = SelectedItemTag Then
                Return I
            End If
        Next
        Return -1
    End Function
    ''' <summary>
    ''' Gibt die Zahl der Items zurueck
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetItemZahl() As Integer
        Return Tags.Length
    End Function
    Public Sub SetItem(ByVal ItemID As Integer)
        If ItemID < Tags.Length Then
            SetItem(Tags(ItemID))
        End If
    End Sub
    Public Overrides Function Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean

    End Function
    Public Overrides Function MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean
        If IsVisble(16) Then
            If (Not HasFocus) Or Focused Then
                e = New System.Windows.Forms.MouseEventArgs(e.Button, e.Clicks, e.X, e.Y, e.Delta)
                'Wir haben keine Zugriffsrechte auf diesen Befehl
                If Netzmodus = False Then Exit Function
                Dim P As Point = GetRealKoordinaten()
                Dim StartRechteck As New Rectangle(P.X, 2 + P.Y, 16 + Rechteck.Width, 17)
                If Focused Then
                    Dim ValueBreite As Integer = 21 * (MaxItems - 1)
                    StartRechteck.Height += ValueBreite + 22
                    If Ausfahrrichtung < 0 Then
                        StartRechteck = New Rectangle(P.X, P.Y - ValueBreite - 22, 16 + Rechteck.Width, 17 + ValueBreite)
                    End If
                    If StartRechteck.Contains(e.X, e.Y) Then
                        If Ausfahrrichtung < 0 Then
                            If New Rectangle(P.X + Rechteck.Width + 4, P.Y - ValueBreite - 22, 16, ValueBreite + 22).Contains(e.X, e.Y) Then
                                If New Rectangle(P.X + Rechteck.Width + 4, P.Y - ValueBreite - 22, 16, 11).Contains(e.X, e.Y) Then
                                    StartIndex -= 1
                                ElseIf New Rectangle(P.X + Rechteck.Width + 4, P.Y - 11, 16, 11).Contains(e.X, e.Y) Then
                                    StartIndex += 1
                                Else
                                    Aktiv = True
                                End If
                                If StartIndex > Items.Length - MaxItems Then StartIndex = Items.Length - MaxItems
                                If StartIndex < 0 Then StartIndex = 0
                                Exit Function
                            End If
                        Else
                            If New Rectangle(P.X + Rechteck.Width + 4, P.Y + 21, 16, ValueBreite + 22).Contains(e.X, e.Y) Then
                                If New Rectangle(P.X + Rechteck.Width + 4, P.Y + 21, 16, 11).Contains(e.X, e.Y) Then
                                    Buttonaktiv = -1
                                ElseIf New Rectangle(P.X + Rechteck.Width + 4, P.Y + 21 + 11 + ValueBreite, 16, 11).Contains(e.X, e.Y) Then
                                    Buttonaktiv = 1
                                Else
                                    Aktiv = True
                                End If
                                If StartIndex < 0 Then StartIndex = 0
                                If StartIndex > Items.Length - MaxItems Then StartIndex = Items.Length - MaxItems
                                Exit Function
                            End If
                        End If
                    End If
                    StartRechteck = New Rectangle(P.X, P.Y, Rechteck.Width, Rechteck.Height)
                    If Ausfahrrichtung > 0 Then
                        StartRechteck.Y += 21
                    Else
                        StartRechteck.Y -= 21
                    End If
                    Dim Max As Integer = Items.Length
                    If Max > MaxItems Then Max = MaxItems
                    For I = StartIndex To StartIndex + Max - 1
                        If StartRechteck.Contains(e.X, e.Y) Then
                            If Ausfahrrichtung < 0 Then
                                SelectedItemTag = Tags(Items.Length - StartIndex * 2 - Max + I)
                                SelectedItem = Items(Items.Length - StartIndex * 2 - Max + I)
                            Else
                                SelectedItemTag = Tags(I)
                                SelectedItem = Items(I)
                            End If

                            Exit For
                        End If
                        If Ausfahrrichtung > 0 Then
                            StartRechteck.Y += 21
                        Else
                            StartRechteck.Y -= 21
                        End If
                    Next
                    RemoveFocus()

                Else
                    If StartRechteck.Contains(e.X, e.Y) Then
                        Focus()
                    End If
                End If
            End If
        End If
    End Function
    Public Overrides Function MouseEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean
        If IsVisble(16) Then
            'Wir haben keine Zugriffsrechte auf diesen Befehl
            If Netzmodus = False Then Exit Function
            e = New System.Windows.Forms.MouseEventArgs(e.Button, e.Clicks, e.X, e.Y, e.Delta)
            If Focused Then
                If Aktiv = True Then
                    If Ausfahrrichtung > 0 Then
                        Dim MaxValue As Integer = Items.Length - MaxItems
                        Dim ValueBreite As Integer = 21 * (MaxItems - 1)
                        Dim P As Point = GetRealKoordinaten()
                        If e.Y < P.Y + 11 Then
                            StartIndex = 0
                        ElseIf e.Y > P.Y + ValueBreite + 21 Then
                            StartIndex = MaxValue
                        Else
                            StartIndex = (e.Y - P.Y - 21 - 11) * (MaxValue) / (ValueBreite - 15)
                        End If
                        If StartIndex < 0 Then StartIndex = 0
                        If StartIndex > MaxValue Then StartIndex = MaxValue
                    Else
                        Dim MaxValue As Integer = Items.Length - MaxItems
                        Dim ValueBreite As Integer = 21 * (MaxItems - 1)
                        Dim P As Point = GetRealKoordinaten()
                        If e.Y > P.Y - 11 Then
                            StartIndex = MaxValue
                        ElseIf e.Y < P.Y - ValueBreite - 22 Then
                            StartIndex = 0
                        Else
                            StartIndex = (e.Y - P.Y + ValueBreite) * (MaxValue) / (ValueBreite - 15)
                        End If
                        If StartIndex < 0 Then StartIndex = 0
                        If StartIndex > MaxValue Then StartIndex = MaxValue

                    End If
                Else
                    Dim Startrechteck As Rectangle = New Rectangle(GetRealX, GetRealY, Rechteck.Width, Rechteck.Height)
                    If Ausfahrrichtung > 0 Then
                        Startrechteck.Y += 21
                    Else
                        Startrechteck.Y -= 21
                    End If
                    Dim Max As Integer = Items.Length
                    If Max > MaxItems Then Max = MaxItems
                    For I = StartIndex To StartIndex + Max - 1
                        If Startrechteck.Contains(e.X, e.Y) Then
                            CursorRechteck = Startrechteck
                            Exit Function
                        End If
                        If Ausfahrrichtung > 0 Then
                            Startrechteck.Y += 21
                        Else
                            Startrechteck.Y -= 21
                        End If
                    Next
                    CursorRechteck = Nothing
                End If
            End If
        End If
    End Function
    Public Overrides Function MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As String
        If IsVisble(16) Then
            If (Not HasFocus) Or Focused Then
                Aktiv = False
                Buttonaktiv = 0
            End If
        End If
        Return ""
    End Function
    Public Overrides Function KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean

    End Function


    Public Overrides Sub Malen()
        If Handler IsNot Nothing Then
            If Not Handler.IsVisible(New Rectangle(Koordinaten.X, Koordinaten.Y, Rechteck.Width + 16, Rechteck.Height), True) Then
                Exit Sub
            End If
        End If
        'Mal sehen ob wir nach unten ausfahren koennen.
        Dim Int As Integer = MaxItems
        If MaxItems > Items.Length Then Int = Items.Length
        If Int * 21 + 21 + GetRealY() > DataSettings.BildschirmHoehe - 20 Then
            Ausfahrrichtung = -1
            If StartIndex > Items.Length - MaxItems Then StartIndex = Items.Length - MaxItems
            If StartIndex < 0 Then StartIndex = 0
        End If

        Dim sngRotation As Double = 0
        Dim intColor As Color = Color.FromArgb(255, 255, 255, 255)
        Grafikengine.ptfRotCenter = Nothing
        Grafikengine.szfScale = Nothing
        Dim P As Point = GetRealKoordinaten()
        Grafikengine.ptfPosition = P
        With Grafikengine.recBild
            .X = 0 : .Width = 2
            .Y = 0 : .Height = 21
        End With
        'links
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        Grafikengine.ptfPosition.X += Rechteck.Width + 15
        Grafikengine.recBild.X = 30
        'rechts
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        Grafikengine.ptfPosition.X = P.X + 2
        With Grafikengine.recBild
            .X = 2 : .Width = 13
            .Y = 0 : .Height = 21
        End With
        Grafikengine.szfScale.Width = Rechteck.Width
        Grafikengine.szfScale.Height = 21
        'Mitte
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        With Grafikengine.recBild
            .X = 16 : .Width = 14
            .Y = 0 : .Height = 21
        End With
        Grafikengine.szfScale = Nothing
        Grafikengine.ptfPosition.X = P.X + 1 + Rechteck.Width
        'Das Symbol
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        'So jetzt muessen wir das aktuelle Symbol malen oder den Text
        Select Case AnzeigeModus
            Case AnzeigeModi.Farben
                Grafikengine.fillRect(New Rectangle(P.X + 1, P.Y + 1, 19, 19), Color.FromArgb(CInt(SelectedItemTag)))
            Case AnzeigeModi.Text
                If Text IsNot Nothing Then
                    'Wir malen den angezeigten Text
                    Text.neuerText(New String() {SelectedItem}, P.X + 2, P.Y + 2, Nothing)
                    Schriftengine.DrawText(Text, New Point)
                End If
        End Select


        If Focused Then
            'Das Objekt hat den Focus, das bedeutet wir malen das ausgefahrene Menue
            DrawAusgefahrenesMenue(P)
        End If

    End Sub
    Private Sub DrawAusgefahrenesMenue(ByVal P As Point)
        Dim intcolor As Color = Color.FromArgb(255, 255, 255, 255)
        Dim sngrotation As Single = 0
        If Ausfahrrichtung > 0 Then
            Grafikengine.ptfPosition = New Drawing.Point(P.X, P.Y + 21)
        Else
            Grafikengine.ptfPosition = New Drawing.Point(P.X, P.Y - 21)
        End If
        'Zuerst Malen wir die Item Hintergruende
        Dim Max As Integer = Items.Length
        If Max > MaxItems Then Max = MaxItems
        For I = StartIndex To StartIndex + Max - 1
            DrawItemBackground(Grafikengine.ptfPosition.Y, TexturenHalter.GetDropDownItemTexturen(0), P)
            If Ausfahrrichtung > 0 Then
                Grafikengine.ptfPosition.Y += 21
            Else
                Grafikengine.ptfPosition.Y -= 21
            End If
        Next
        'Wir malen die Items.
        Select Case AnzeigeModus
            Case AnzeigeModi.Farben
                Dim YStart As Integer
                If Ausfahrrichtung > 0 Then
                    YStart = P.Y + 21
                Else
                    YStart = P.Y - 21
                End If
                If Ausfahrrichtung < 0 Then
                    Dim I As Integer = Max - 1
                    For I2 = Items.Length - StartIndex - Max To Items.Length - StartIndex - 1
                        Grafikengine.fillRect(New Rectangle(P.X + 1, YStart, 21, 19), Color.FromArgb(CInt(Tags(I2))))
                        YStart -= 21
                    Next
                Else
                    For I2 = StartIndex To StartIndex + Max - 1
                        Grafikengine.fillRect(New Rectangle(P.X + 1, YStart, 21, 19), Color.FromArgb(CInt(Tags(I2))))
                        YStart += 21
                    Next
                End If

                'Wir wollen Farb Quadrate anzeigen.
                'Dim Pos As New Point
                'If Ausfahrrichtung > 0 Then
                '    Pos = New Drawing.Point(P.X + 1, P.Y + 22)
                'Else
                '    Pos = New Drawing.Point(P.X - 1, P.Y + 22)
                'End If
                'For I2 = StartIndex To StartIndex + Max - 1
                '    Grafikengine.fillRect(New Rectangle(Pos.X, Pos.Y, 21, 19), Color.FromArgb(CInt(Tags(I2))))
                '    If Ausfahrrichtung > 0 Then
                '        Pos.Y += 21
                '    Else
                '        Pos.Y -= 21
                '    End If
                'Next
            Case AnzeigeModi.Text
                'Wir wollen einen Text anzeigen
                Dim T(Max - 1) As String
                If Ausfahrrichtung < 0 Then
                    Dim I As Integer = Max - 1
                    For I2 = Items.Length - StartIndex - Max To Items.Length - StartIndex - 1
                        T(I) = Items(I2)
                        I -= 1
                    Next
                Else
                    For I2 = StartIndex To StartIndex + Max - 1
                        T(I2 - StartIndex) = Items(I2)
                    Next
                End If
                Dim Farben() As Color = {Color.Black}
                Dim YStart As Integer
                If Ausfahrrichtung > 0 Then
                    YStart = P.Y + 21
                Else
                    YStart = P.Y - 21 * (Max - 1) - 21
                End If
                Text.neuerText(T, P.X + 1, YStart + 3, Farben, , 5)
                Grafikengine.Sprite.Transform = Matrix.Identity
                Text.Malen(New Point)
        End Select
        'Eventuell den Scrollbar malen
        If Items.Length > MaxItems Then
            DrawScrollBar(P)
        End If
        'Jetzt noch das Cursorrechteck
        If Not CursorRechteck = Nothing Then
            'Jetzt wird der Cursor gemalt
            DrawItemBackground(CursorRechteck.Y, TexturenHalter.GetDropDownItemTexturen(1), P, CursorRechteck.X)
        End If

    End Sub
    Private Sub DrawItemBackground(ByVal Y As Integer, ByVal BildTextur As Texture, ByVal P As Point, Optional ByVal X As Integer = -1)
        Dim sngRotation As Double = 0
        Dim intColor As Color = Color.FromArgb(255, 255, 255, 255)
        Grafikengine.ptfRotCenter = Nothing
        Grafikengine.szfScale = Nothing
        Grafikengine.ptfPosition.Y = Y
        If X > 0 Then
            Grafikengine.ptfPosition.X = X
        Else
            Grafikengine.ptfPosition.X = P.X
        End If
        With Grafikengine.recBild
            .X = 0 : .Width = 2
            .Y = 0 : .Height = 21
        End With
        'links
        Grafikengine.Sprite.Draw2D(BildTextur, Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        Grafikengine.ptfPosition.X += Rechteck.Width + 2
        Grafikengine.recBild.X = 23
        'rechts
        Grafikengine.Sprite.Draw2D(BildTextur, Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        Grafikengine.ptfPosition.X = P.X + 2
        With Grafikengine.recBild
            .X = 2 : .Width = 21
            .Y = 0 : .Height = 21
        End With
        Grafikengine.szfScale.Width = Rechteck.Width
        Grafikengine.szfScale.Height = 21
        'Mitte
        Grafikengine.Sprite.Draw2D(BildTextur, Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)

    End Sub
    ''' <summary>
    ''' Unvollstaendig
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub DrawScrollBar(ByVal P As Point)
        Dim sngRotation As Double = 0
        Dim intColor As Color = Color.FromArgb(255, 255, 255, 255)
        Dim ValueBreite As Integer = 21 * (MaxItems - 1)
        Grafikengine.ptfRotCenter = New Point(0, 0)

        With Grafikengine.recBild
            .X = 0 : .Width = 16
            .Y = 0 : .Height = 11
        End With

        Grafikengine.ptfPosition = P
        Grafikengine.szfScale = Nothing
        'wir malen den oberen Pfeil
        If Ausfahrrichtung > 0 Then
            Grafikengine.ptfPosition.Y += 21
            Grafikengine.ptfPosition.X += 4 + Rechteck.Width
        Else
            Grafikengine.ptfPosition = New Point(P.X + Rechteck.Width + 4, P.Y - ValueBreite - 11 - 11)
        End If
        Grafikengine.Sprite.Draw2D(TexturenHalter.GetDropDownItemTexturen(2), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        'wir malen den Unteren Pfeil
        With Grafikengine.recBild
            .X = 0 : .Width = 16
            .Y = 41 : .Height = 11
        End With
        If Ausfahrrichtung > 0 Then
            Grafikengine.ptfPosition = New Point(P.X + Rechteck.Width + 4, P.Y + ValueBreite + 21 + 11)
        Else
            Grafikengine.ptfPosition.Y = P.Y - 11
            Grafikengine.ptfPosition.X = P.X + 4 + Rechteck.Width
        End If

        Grafikengine.Sprite.Draw2D(TexturenHalter.GetDropDownItemTexturen(2), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)

        'Wir finden heraus wie oft wir den Mittelteilmalen muessen
        Dim Breite As Integer = Divi(ValueBreite, 15)
        'Wir malen alle Mittelteile bis auf den letzten
        With Grafikengine.recBild
            .X = 0 : .Width = 16
            .Y = 26 : .Height = 15
        End With
        If Ausfahrrichtung > 0 Then
            Grafikengine.ptfPosition.Y = P.Y + 21 + 11
        Else
            Grafikengine.ptfPosition.Y = P.Y - ValueBreite - 11
        End If
        For I = 0 To Breite - 2
            Grafikengine.Sprite.Draw2D(TexturenHalter.GetDropDownItemTexturen(2), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
            Grafikengine.ptfPosition.Y += 15
        Next
        'Der letzte wird jetzt gemalt, weil er eine Ausnahme ist.
        If Ausfahrrichtung > 0 Then
            Grafikengine.ptfPosition.Y = P.Y + 21 + 11 + ValueBreite - 15
        Else
            Grafikengine.ptfPosition.Y = P.Y - 11 - 15
        End If

        Grafikengine.Sprite.Draw2D(TexturenHalter.GetDropDownItemTexturen(2), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        'So jetzt muessen wir noch den Regler malen
        'So das waere der Nullwert des Reglers
        If Ausfahrrichtung > 0 Then
            Grafikengine.ptfPosition.Y = P.Y + 21 + 11
        Else
            Grafikengine.ptfPosition.Y = P.Y - 15 - 11
        End If

        'Jetzt addieren wir seine Verschiebung drauf.
        If Ausfahrrichtung > 0 Then
            Grafikengine.ptfPosition.Y += (StartIndex) / (Items.Length - MaxItems) * (ValueBreite - 15)
        Else
            Grafikengine.ptfPosition.Y += (StartIndex) / (Items.Length - MaxItems) * (ValueBreite - 15) - ValueBreite + 15
        End If


        With Grafikengine.recBild
            .X = 0 : .Width = 16
            .Y = 11 : .Height = 15
        End With

        Grafikengine.Sprite.Draw2D(TexturenHalter.GetDropDownItemTexturen(2), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)

        If Frame2 > 2 Then
            Frames()
            Frame2 = 0
        Else
            Frame2 += 1
        End If

    End Sub
    Private Sub Frames()
        If Buttonaktiv <> 0 Then
            Dim MaxValue As Integer = Items.Length - MaxItems
            StartIndex += 1 * Ausfahrrichtung * Buttonaktiv
            If StartIndex < 0 Then StartIndex = 0
            If StartIndex > MaxValue Then StartIndex = MaxValue
        End If
    End Sub

    Public Overrides Sub RemoveHandles()
        MyBase.RemoveHandles()
    End Sub
    Public Overrides Sub ChangeWindowSize(ByVal PosChange As System.Drawing.Point)
        MyBase.ChangeWindowSize(PosChange)
        Bildgroesse.X += PosChange.X * Fixed.X
        Bildgroesse.Y += PosChange.Y * Fixed.Y
    End Sub

    Public Overloads Overrides Function MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean

    End Function
End Class
